package com.xm.xmapp.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.xm.xmapp.R;
import com.xm.xmapp.myinterface.MyDialogButton;
import com.xm.xmapp.response.bean.NoticeResponse;
import com.xm.xmapp.tools.Options;

public class NoticeTipDialog extends Dialog {
	private Context context;
	private NoticeResponse bean;
	private MyDialogButton in;

	public NoticeTipDialog(Context context, NoticeResponse bean,MyDialogButton in) {
		super(context, R.style.Dialog);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.bean = bean;
		this.in = in;

	}

	@SuppressLint("InflateParams")
	public void init() {
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.dialog_notice_tip, null);
		TextView title = (TextView) view.findViewById(R.id.title);
		TextView time = (TextView) view.findViewById(R.id.time); 
		TextView address = (TextView) view.findViewById(R.id.address); 
		TextView content = (TextView) view.findViewById(R.id.content);
		
		
		ImageView img = (ImageView) view.findViewById(R.id.img);
		ImageView x = (ImageView) view.findViewById(R.id.x);
		ImageView onclick = (ImageView) view.findViewById(R.id.onclick);
		
		title.setText(bean.title);
		content.setText(bean.description);
		time.setText("时间："+bean.valid_start_time+"——"+bean.valid_end_time);
		address.setText("地点："+bean.address);
		
		ImageLoader.getInstance().displayImage(bean.image, img,
				Options.getListOptions(R.mipmap.noticefly));
		
		
		x.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				context = null;
				dismiss();
			}
		});

		onclick.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				
				context = null;
				dismiss();
				if(in!=null)
				{
					in.setTitle(0, "");
				}

			}
		});

		setContentView(view);

//		Window dialogWindow = getWindow();
//		WindowManager.LayoutParams lp = dialogWindow.getAttributes();
//		DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
//		lp.width = (int) (d.widthPixels * 0.8); // 高度设置为屏幕的0.6
//		dialogWindow.setAttributes(lp);
	}



	@Override
	public void show() {
		// TODO Auto-generated method stub
		super.show();
	
		setCancelable(false);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		init();

	}

}
